package edu.ucdavis.gwt.gis.client.toolbar.button;

import java.util.LinkedList;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.user.client.ui.Image;

import edu.ucdavis.gwt.gis.client.DataManager;
import edu.ucdavis.gwt.gis.client.export.LegendExporter;
import edu.ucdavis.gwt.gis.client.layers.DataLayer;
import edu.ucdavis.gwt.gis.client.resources.GadgetResources;
import edu.ucdavis.gwt.gis.client.toolbar.Toolbar;

public class LegendExporterButton extends ToolbarItem {

	private Image img = new Image();
	
	@Override
	public Image getIcon() {
		img.setResource(GadgetResources.INSTANCE.exportLegend());
		img.setTitle("Export Legend");
		return img;
	}

	@Override
	public void onAdd(Toolbar toolbar) {}

	@Override
	public void onClick(ClickEvent event) {
		LegendExporter.INSTANCE.clearLayers();
		LinkedList<DataLayer> layers = DataManager.INSTANCE.getDataLayers();
		for( DataLayer dl: layers ) {
			LegendExporter.INSTANCE.addLayer(dl);
		}
		LegendExporter.INSTANCE.export();
	}
	
	//public void addLayerInfo(JsArray<LayerInfo> layers, String name){
	//	legendExporter.addLayer(layers, name);
	//}

	@Override
	public String getText() {
		return "Export Legend";
	}

}
